package com.itheima.threadapidemo;

public class ThreadApiDemo3 {

    public static void main(String[] args) {
        Thread t = new MyThread();
        t.start();

        for (int i = 0; i < 100; i++){
            System.out.println(Thread.currentThread().getName() + ":" + i);
            if(i == 20){
                try {
                    // main线程等待t线程执行完毕
                    t.join();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}

class MyThread extends Thread {
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName() + ":" + i);
        }
    }
}
